package com.chinasoft.controller;


import com.chinasoft.pojo.TopCategory;
import com.chinasoft.pojo.TopItems;
import com.chinasoft.result.Result;
import com.chinasoft.service.TopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("top")
@CrossOrigin
public class TopController {

    @Autowired
    private TopService topService;

    /**
     * 获取topN品类
     * @param limit 所需查询的topN品类数量
     */
    @GetMapping("categories")
    public Result<List<TopCategory>> getTopCategories(@RequestParam(defaultValue = "10") Integer limit) {
        List<TopCategory> topCategories = topService.getTopCategories(limit);
        return Result.success(topCategories);
    }

    /**
     * 获取topN商品
     * @param limit 所需查询的topN商品数量
     */
    @GetMapping("items")
    public Result<List<TopItems>> getTopItems(@RequestParam(defaultValue = "10") Integer limit) {
        List<TopItems> topItems = topService.getTopItems(limit);
        return Result.success(topItems);
    }
}
